package com.lvt.example.thinking.in.spring.questions.L20.bean.dependcy;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * desc：StudentController
 *
 * @author LT
 * @date 2022/10/16
 */
@RestController
@Slf4j
@Validated
public class StudentController {
//    @Autowired
    // 修改方式三
//    @Qualifier("cassandraDataService")
//    DataService dataService;
    // 修改方式2，直接使用属性名精准匹配
//            DataService oracleDataService;

    @Autowired
    @Qualifier("studentController.InnerClassDataService")
    DataService innerClassDataService;

    @RequestMapping(path = "students/{id}", method = RequestMethod.DELETE)
    public void deleteStudent(@PathVariable("id") @Range(min = 1, max = 100) int id) {
//        oracleDataService.deleteStudent(id);
        innerClassDataService.deleteStudent(id);
    }

    @Repository
    public static class InnerClassDataService implements DataService {

        @Override
        public void deleteStudent(int id) {
            System.out.println("InnerClassDataService delete");
        }
    }

    private List<Student> students;

    public StudentController(List<Student> students) {
        this.students = students;
    }

    @RequestMapping(path = "students", method = RequestMethod.GET)
    public String listStudents() {
        return students.toString();
    }

    ;

}